﻿using System;
using System.Web;

namespace Yd.HttpHandler
{
    public class HandlerFactory : IHttpHandlerFactory
    {
        const string _namespace = "Yd.HttpHandler.";

        #region IHttpHandlerFactory 成员
        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            string fname = url.Substring(url.LastIndexOf('/') + 1);
            string cname = fname.Substring(0, fname.IndexOf('.'));
            string className = _namespace + cname;
            object h = null;
            try
            {
                h = Activator.CreateInstance(Type.GetType(className));
                //对地址栏传过来的参数进行检测
                //if (!JinceQuery(context))
                //{
                //    CommCls.CommUtils.ShowMessaegError(context, "抱歉! 您输入的数据包含非法字符串或您访问的资源不存在!");
                //    return null;
                //}
            }
            catch (Exception e)
            {
                //lgdal.LocalLog("HandlerFactory:" + cname + "-创建失败!" + e.Message);
                //CommCls.CommUtils.ShowMessaegError(context, "抱歉! 您输入的数据包含非法字符串或您访问的资源不存在!!");
                throw new HttpException("Factory couldn't create instance " +
                                    "of type " + className, e);

            }
            return (IHttpHandler)h;
        }

        public void ReleaseHandler(IHttpHandler handler)
        {
        }
        #endregion
    }
}
